package com.zhku.meeting.controller;

import com.zhku.meeting.entities.Msg;
import com.zhku.meeting.service.StaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zhku.meeting.Annotation.loginCharacter;

import java.util.Map;

@RestController
public class StaffController {
    @Autowired
    private StaffService staffService;

    //根据ID查员工信息
//    @loginCharacter
    @GetMapping("/staff")
    public Msg getStaff(@RequestParam Map<String,Object> para){
        return staffService.getStaff(para);
    }

    //分页查询所有员工信息
//    @loginCharacter
    @GetMapping("/staffs")
    public Msg getAllStaff(@RequestParam Map<String,Object> para){
        return staffService.getAll(para);
    }

    //添加员工
    @loginCharacter
    @PostMapping("/staff")
    public Msg add(@RequestBody Map<String,Object> para){
        Msg msg = staffService.duplicateCheck1(para);
        if (msg.getCode()==200){
            return msg;
        }
        return staffService.addStaff(para);
    }

    //id删除员工
    @loginCharacter
    @DeleteMapping("/staff")
    public Msg delete(@RequestBody Map<String,Object> para){
        return staffService.deleteById(para);
    }

    //修改员工信息
    @loginCharacter
    @PutMapping("/staff")
    public Msg update(@RequestBody Map<String,Object> para){
        Msg msg = staffService.duplicateCheck(para);
        return msg.getCode()==200?msg:staffService.updateStaff(para);
    }

    //修改员工信息
//    @loginCharacter
    @PutMapping("staffs")
    public Msg updateStaff(@RequestBody Map<String,Object> para){
        Msg msg = staffService.duplicateCheck(para);
        return msg.getCode()==200?msg:staffService.userUpdateStaff(para);
    }
    //模糊查询
//    @loginCharacter
    @GetMapping("/staffCondition")
    public Msg selectCondition(@RequestParam Map<String,Object> para){
        return staffService.selectCondition(para);
    }

    //重置密码
    @loginCharacter
    @GetMapping("/reset")
    public Msg reset(@RequestParam Map<String,Object> para){
        return staffService.resetPassword(para);
    }
}
